//
//  YUYAMeViewController.m
//  com.yigu.yuya
//
//  Created by hxp on 16/3/2.
//  Copyright © 2016年 hxp. All rights reserved.
// 关于雅同界面

#import "YAYIAboutViewController.h"
#import "YAYLliabilityViewController.h"

#import "YAYIAboutCell.h"
#import "YAYISettingSectionModel.h"
#import "YAYISettingItemModel.h"





#define YAYIShockSwitch 400
#define YAYIVoiceSwitch 401

#define YAYIShockID @"YAYIShockID"
#define YAYIVoiceID @"YAYIVoiceID"


@interface YAYIAboutViewController ()

@property (nonatomic, weak) UIView *footerView;
@property (strong,nonatomic) UIButton *backBtn;

@end

@implementation YAYIAboutViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"关于";
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    //    self.tableView.separatorInset = UIEdgeInsetsZero;
    [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    //self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorColor = YAYICellLineColor;
    
    
    [self setupHeaderView];
    
    // 添加组
    [self setupSection0];
}


- (void)setupHeaderView
{
    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0, 0, SCREEN_width, SCREEN_height * 0.35);
//    view.backgroundColor = [UIColor redColor];
    
    // 图标
    UIImageView *imgView = [[UIImageView alloc] init];
//    imgView.backgroundColor = [UIColor lightGrayColor];
    imgView.image = [UIImage imageNamed:@"personalIcon"];
    imgView.layer.cornerRadius = 18;
    imgView.clipsToBounds = YES;
    [view addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@110);
        make.center.equalTo(view);
        make.centerY.equalTo(view.mas_centerY).offset(-10);
    }];
    
    // 文字
    NSString *curVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    UILabel *versionTitleLbl = [[UILabel alloc] init];
    versionTitleLbl.textAlignment = NSTextAlignmentCenter;
    versionTitleLbl.font = [UIFont systemFontOfSize:18];
    versionTitleLbl.textColor = YAYIColor(72, 69, 72);
    versionTitleLbl.text = [NSString stringWithFormat:@"雅同医生端v%@", curVersion];
    [view addSubview:versionTitleLbl];
    
    [versionTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@30);
        make.width.equalTo(view);
        make.centerX.equalTo(view);
        make.top.equalTo(imgView.mas_bottom).offset(15);
    }];
    
    
    
    self.tableView.tableHeaderView = view;
    
}


- (void)setupSection0
{
    YAYISettingItemModel *item0 = [YAYISettingItemModel itemWithIcon:nil name:@"客服电话" detail:@"0571-81182533"];
//    item0.isHaveArrow = NO;
    
    item0.executeOperation = ^(NSIndexPath *indexPath){
        YAYILog(@"密码修改");
    };
    
    YAYISettingItemModel *item1 = [YAYISettingItemModel itemWithIcon:nil name:@"客服邮箱" detail:@"kefu@yayi365.cn"];
//    item1.isHaveArrow = NO;
    
    YAYISettingItemModel *item2 = [YAYISettingItemModel itemWithIcon:nil name:@"微信公众号" detail:@"雅同"];
//    item2.isHaveArrow = NO;
    
    YAYISettingItemModel *item3 = [YAYISettingItemModel itemWithIcon:nil name:@"免责声明"];
    item3.destVcClass = [YAYLliabilityViewController class];
    
    YAYISettingSectionModel *section0 = [[YAYISettingSectionModel alloc]init];
    section0.itemArray = @[item0, item1, item2, item3];
    
    [self.sectionArray addObject:section0];
}




#pragma mark - 按钮相应方法
- (void)quitClick:(UIButton *)sender
{
    YAYILog(@"quitClick");
}

- (void)switchClick:(BOOL)isOn indexPath:(NSIndexPath *)indexPath
{
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if (0 == indexPath.row) {
        [userDefaults setBool:isOn forKey:YAYIVoiceID];
    }else if (1 == indexPath.row){
        [userDefaults setBool:isOn forKey:YAYIShockID];
    }
}

#pragma mark - 代理方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 去除数据模型
    YAYISettingSectionModel *section = self.sectionArray[indexPath.section];
    YAYISettingItemModel *model = section.itemArray[indexPath.row];

    YAYIAboutCell *cell = [YAYIAboutCell cellWith:tableView];
    cell.model = model;
    cell.detailTextLabel.textAlignment = NSTextAlignmentLeft;
    
    if (section.itemArray.count - 1 != indexPath.row) {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}


//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//}


@end
